<template>
  <el-dialog title="是否支持超时配送短信" :visible.sync="visible" width="600px">
    <div class="form">
      <el-form ref="form" :model="form" label-width="200px">
        <el-form-item label="城市">
          {{itemData.deptName}}
        </el-form-item>
        <el-form-item label="是否支持超时配送短信">
          <el-switch v-model="form.isOverTimeSms" :active-value="1" :inactive-value="0"></el-switch>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { editDeliverySms } from '@/api/system/dept'
export default {
  props: {
  },
  data() {
    return {
      visible: false,
      itemData: {},
      form: {
        isOverTimeSms: 0,
      },
    }
  },
  methods: {
    show(data) {
      this.visible = true
      this.itemData = data
      this.form.isOverTimeSms = data.isOverTimeSms || 0
    },
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          const params = this.getParams()
          editDeliverySms(params).then(res => {
            if (res.data.code === 200) {
              this.$message({
                type: 'success',
                message: '编辑成功！'
              })
              this.visible = false
              this.$emit('editSuccess')
            }
          })
        }
      })
    },
    getParams() {
      const params = {
        ...this.form,
        id: this.itemData.id,
      }
      return params
    }
  },
}
</script>

<style lang="scss" scoped>
</style>
